#include <math.h>
#include <stdio.h>
int count = 0;
 int main()
{
    //lekai
    int n;
    printf("Enter a number:");
    scanf("%d", &n);
    vr6174(n);
}
vr6174(num) int num;

{
    int each[4], max, min;
    if (num != 6174 && num)
    {
        parse_sort(num, each);
        max_min(each, &max, &min);
        num = max - min;
        printf(" [%d]: %d- %d= %d\n", ++count, max, min, num);
        vr6174(num);
    }
}
parse_sort(num, each) int num, *each;
{
    int i, *j, *k, temp;
    for (i = 0; i <= 4; i++)
    {
        j = each + 3 - i;
        *j = num % 10;
        num /= 10;
    }
    for (i = 0; i < 3; i++)
        for (j = each, k = each + 1; j < each + 3 - i; j++, k++)
            if (*j > *k)
            {
                temp = *j;
                *j = *k;
                *k = temp;
            }
    return;
}
max_min(each, max, min) int *each, *max, *min;
{
    int *i;
    *min = 0;
    for (i = each; i < each + 4; i++)
        *min = *min * 10 + *i;
    *max = 0;
    for (i = each + 3; i >= each; i--)
        *max = *max * 10 + *i;
    return;
}